package com.shiguiwu.springmybatis.spring.conditional;

import com.shiguiwu.springmybatis.spring.conditional.annotation.MyEnvCondition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

/**
 * @description: 配置类
 * @author: stone
 * @date: Created by 2021/3/15 12:09
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.spring.conditional
 */
//@Conditional(value = MyCondition.class)
@ComponentScan
public class ConditionalConfig {

    @Bean
//    @Conditional(OnMissingBeanCondition.class)
    public ICondition conditionalBean() {
        return new ConditionalBean();
    }

    //条件
    @Conditional(OnMissingBeanCondition.class)
    @Bean
    public ICondition conditionalBean1() {
        return new ConditionalBean();
    }


    @Configuration
    @MyEnvCondition(MyEnvCondition.Env.DEV)
    public static class DevConfig {

        @Bean
        public String username2() {
            return "开发环境";
        }

    }

    @Configuration
    @MyEnvCondition(MyEnvCondition.Env.TEST)
    public static class TestConfig {

        @Bean
        public String username2() {
            return "测试环境";
        }

    }

    @Configuration
    @MyEnvCondition(MyEnvCondition.Env.PRODUCT)
    public static class ProConfig {

        @Bean
        public String username2() {
            return "生产环境";
        }

    }
}
